const state = {
    //登录的用户
    user: "",
    friendData: [],
    attention: [],
    delCarItem: '',
    num: 0,
    treeData: [
        {
            talkCon:
                "hi~小朋友你好呀，我是美可，你可以叫我maco哦，你觉得我的故事好听吗?",
            type: "0",
        },
    ],
    scrollTop:'',
    dingyue:'',
    type:false,
    items:''
}

const mutations = {
    dy(state,choose){
        state.dingyue = choose
    },
    myStory(state,item){
        state.items = item 
    },
    choose(state,pd){
        state.type = pd
    },
    addCount(state, counts) {
        state.user = counts
    },
    addFriend(state, arr) {
        state.friendData = arr
    },
    addAttention(state, arr) {
        state.attention = arr
    },
    delCarItem(state, arr) {
        state.delCarItem = arr
    },
    macoNum(state, arr) {
        state.num = arr
    },
    TreeData(state, arr){
        state.treeData=arr
    },
    replaceTreeData(state, obj) {
        let index=Number(state.treeData.length)-1
        state.treeData.splice(index,1,obj)
    },
    addTreeData(state, obj) {
        state.treeData.push(obj)
        let serviceObj={}
        let serviceObj1={}
        setTimeout(()=>{
            if (obj.talkCon.indexOf('好听') !== -1||obj.talkCon.indexOf('喜欢') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!谢谢你对我的认可，我们一定可以成为好朋友的，maco还想问你，你现在开心吗?",
                    type: "0",
                }
            }
            if (obj.talkCon.indexOf('不好听') !== -1||obj.talkCon.indexOf('不喜欢')!== -1) {
                serviceObj= {
                    talkCon:
                        "呜呜呜~，有一点伤心啊，但我会努力让你喜欢上我的",
                    type: "0",
                }
            }
            if (obj.talkCon.indexOf('开心') !== -1) {
                serviceObj= {
                    talkCon:
                        "嘻嘻嘻嘻，我也很开心",
                    type: "0",
                }
            }
            if (obj.talkCon.indexOf('高兴') !== -1) {
                serviceObj= {
                    talkCon:
                        "嘻嘻嘻嘻，我也很高兴",
                    type: "0",
                }
            }
            if (obj.talkCon.indexOf('听故事') !== -1||obj.talkCon.indexOf('看故事') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:Math.floor(Math.random()*39+104),
                    type: "3",
                }
            }
            if (obj.talkCon.indexOf('唐诗') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:'唐诗三百首',
                    type: "4",
                }
            }
            if (obj.talkCon.indexOf('睡前') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:'睡前故事',
                    type: "4",
                }
            }
            if (obj.talkCon.indexOf('习惯') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:'习惯培养',
                    type: "4",
                }
            }
            if (obj.talkCon.indexOf('成长') !== -1||obj.talkCon.indexOf('陪伴') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:'成长陪伴',
                    type: "4",
                }
            }
            if (obj.talkCon.indexOf('防疫') !== -1||obj.talkCon.indexOf('控疫') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:'防疫控疫',
                    type: "4",
                }
            }
            if (obj.talkCon.indexOf('心理') !== -1) {
                serviceObj= {
                    talkCon:
                        "恩恩!好的",
                    type: "0",
                }
                serviceObj1= {
                    talkCon:'心理辅导',
                    type: "4",
                }
            }
            if (obj.talkCon.indexOf('心理') === -1&&obj.talkCon.indexOf('防疫') === -1&&obj.talkCon.indexOf('控疫') === -1&&obj.talkCon.indexOf('成长') === -1&&obj.talkCon.indexOf('陪伴') === -1&&obj.talkCon.indexOf('习惯') === -1&&obj.talkCon.indexOf('睡前') === -1&&obj.talkCon.indexOf('唐诗') === -1&&obj.talkCon.indexOf('类型') !== -1||obj.talkCon.indexOf('心理') === -1&&obj.talkCon.indexOf('防疫') === -1&&obj.talkCon.indexOf('控疫') === -1&&obj.talkCon.indexOf('成长') === -1&&obj.talkCon.indexOf('陪伴') === -1&&obj.talkCon.indexOf('习惯') === -1&&obj.talkCon.indexOf('睡前') === -1&&obj.talkCon.indexOf('唐诗') === -1&&obj.talkCon.indexOf('种类') !== -1) {
                serviceObj= {
                    talkCon:
                        "对不起，您说的类型我无法找到",
                    type: "0",
                }
            }
            state.treeData.push(serviceObj)
            setTimeout(()=>{
                state.treeData.push(serviceObj1)
            },500)
        },1000)
    },
    scrollTop(state,num){
        state.scrollTop=num
    },
}

const actions = {
    addCount({ commit }, count) {
        commit('addCount', count)
    },
    addTreeData({ commit }, obj) {
        commit('addTreeData', obj)
    }
}
const getters = {
    acb(state) {
        let add = state.delCarItem.filter((item, idnex) => {
            return item.flag
        })
        let str = 0
        add.forEach((item) => {
            str += parseInt(state.num)
        })
        return str
    },
    present(state){
        let str = state.delCarItem.filter((item,idnex)=>{
            return item.flag
        })
        return str
    }

}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}